//
//  SinaWelcomeViewController.m
//  oc微博
//
//  Created by 安陆与 on 16/1/19.
//  Copyright © 2016年 安陆与. All rights reserved.
//

#import "SinaWelcomeViewController.h"
#import "Masonry.h"
#import <UIKit/UIKit.h>
#import "AFNetworking.h"
#import "UIImageView+WebCache.h"
#import "SinaAccountViewModel.h"
#import "SVProgressHUD.h"
@interface SinaWelcomeViewController ()

@property (nonatomic, weak) UIImageView *icomImage;

@property (nonatomic, weak) UILabel *nameLabel;

//头像底部的约束
@property (nonatomic, assign) MASConstraint *bottomConstraint;

@end

@implementation SinaWelcomeViewController

-(void)loadView{

    self.view = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ad_background"]];
    
    [self setupUI];
}


-(void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];

    [self.view setNeedsUpdateConstraints];
    [self.view updateConstraintsIfNeeded];
    [self.icomImage mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom).offset(-500);

    }];
    
    [UIView animateWithDuration:2 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0 options:0 animations:^{
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        
        [[NSNotificationCenter defaultCenter]postNotificationName:@"change" object:nil];
    }];

}



//设置ui
-(void)setupUI{

    
    //添加头像
    UIImageView *iconImage = [[UIImageView alloc]init];

    self.icomImage = iconImage;
    
    [self.view addSubview:iconImage];
    
    iconImage.layer.masksToBounds = YES;
    
    iconImage.layer.cornerRadius = 170 * 0.5 * 0.5;
    
    iconImage.layer.borderWidth = 3;
    
    iconImage.layer.borderColor = [UIColor whiteColor].CGColor;
    
    [iconImage setImage:[UIImage imageNamed:@"avatar_default_big"]];
    
    
//            [iconImage sd_setImageWithURL:[NSURL URLWithString:@"http://tp2.sinaimg.cn/5822999257/50/5748156804/1"]];
//
//    if ([[SinaAccountViewModel alloc]init].profile_image_url) {
//        
//        NSLog(@"%@",[[SinaAccountViewModel alloc]init].profile_image_url);
////        [iconImage sd_setImageWithURL:[NSURL URLWithString:[[SinaAccountViewModel alloc]init].profile_image_url]];
//        [iconImage sd_setImageWithURL:[NSURL URLWithString:@"http://tp2.sinaimg.cn/5822999257/50/5748156804/1"]];
//        
//        
//    }else{
//    
//        [iconImage setImage:[UIImage imageNamed:@"avatar_default_big"]];
//
//    
//    }
    

    
    //头像的约束
    [iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        self.bottomConstraint = make.bottom.equalTo(self.view.mas_bottom).offset(-150);
        
    }];
    
    //添加欢迎回来label
    UILabel *nameLabel = [[UILabel alloc]init];
    
    [self.view addSubview:nameLabel];
    
    self.nameLabel = nameLabel;
    
    [nameLabel setText:@"欢迎回来"];
    
    nameLabel.textAlignment = 0;
    
    nameLabel.textColor = [UIColor blackColor];
    
    nameLabel.font = [UIFont systemFontOfSize:16];
    
    //添加约束
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        
        make.centerX.equalTo(self.view.mas_centerX);
        
        make.top.equalTo(self.icomImage.mas_bottom).offset(20);
        
    }];

}


@end
